package org.hitchhike.core.domain;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hitchhike.common.domain.BaseEntity;
import org.hitchhike.core.enums.Constant;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@Entity
@Table(name = "tb_order_detail")
@EqualsAndHashCode(callSuper = false)
public class OrderDetail extends BaseEntity {

  @ManyToOne(fetch = FetchType.LAZY)
  private Order order;

  @ManyToOne(fetch = FetchType.LAZY)
  private User user;

  private Integer state;

  public String getStateName() {
    String stateName = "";
    switch (this.state) {
      case Constant.ORDER_DETAIL_STATE_0:
        stateName = "取消";
        break;
      case Constant.ORDER_DETAIL_STATE_1:
        stateName = "待定";
        break;
      case Constant.ORDER_DETAIL_STATE_2:
        stateName = "付款";
        break;
      default:
        break;
    }
    return stateName;
  }

  public OrderDetail() {}

  public OrderDetail(Order order, User user, int state) {
    this.order = order;
    this.user = user;
    this.state = state;
  }

}
